package com.fileCenter.service.impl;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

import com.fileCenter.dao.ModelDAO;
import com.fileCenter.exception.FileCenterException;
import com.fileCenter.pojo.Model;
import com.fileCenter.service.ModelService;
import com.fileCenter.util.MD5Util;

public class ModelServiceImpl implements ModelService {
	private ModelDAO modelDao = null;

	@Override
	public Model login(String name, String password)
			throws FileCenterException {
		Model model = modelDao.queryByName(name);
		String loginPwdMd5 = MD5Util.getMD5String(password);
		if (null != model && StringUtils.equals(loginPwdMd5, model.getPassword())) {
			return model;
		}
		return null;
	}
	
	@Override
	public List<Model> listByAttr(Map<String, Object> attrNameAndValueMap)
			throws FileCenterException {
		return modelDao.queryByAttr(attrNameAndValueMap);
	}

	public void setModelDao(ModelDAO modelDao) {
		this.modelDao = modelDao;
	}

}
